package org.footballmanager.pandafootball.common.util;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hssf.usermodel.*;
import org.footballmanager.pandafootball.common.constants.Constants;
import org.footballmanager.pandafootball.common.exception.ExceptionEnum;
import org.footballmanager.pandafootball.common.exception.MyException;
import org.footballmanager.pandafootball.system.domain.PersonFromWeb;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.util.StringUtils;

import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.*;

@Slf4j
public class SpiderUtil implements Runnable {
    private static final String TBODYTR = "tbody tr";
    //用于存放爬取页面的列表页面 转换成 list
    private static List<String> allPageList = new ArrayList<>();
    //用于存放爬取球员信息的url
    private static List<String> playerPageList = new ArrayList<>();

    private static String baseUrl = "http://pesdb.net/pes2018";

    private static List<PersonFromWeb> personList = new ArrayList<>();

    private static StringBuilder result;
    private static List<HSSFRow> rows = new ArrayList<>();

    private SpiderUtil() {
        log.info("---------start-----------" + new Date().getTime());
        Thread thread = new Thread(this);
        thread.start();
        try {
            thread.join();
        } catch (InterruptedException e) {
            log.error(e.getMessage());
            Thread.currentThread().interrupt();
            throw new MyException(ExceptionEnum.INTERRUPTEDEXCEPTION, e);
        }
        log.info("----------end------------" + new Date().getTime());
    }

    private static String findIdByUrl(String url) {
        //http://pesdb.net/pes2018/?id=4522
        return url.replaceAll("http://pesdb.net/pes2018/?id=", "");
    }

    private static PersonFromWeb processPlayerList(Document doc, String id, boolean isProcessImage) {
        if (doc == null) {
            return null;
        }
        if (isProcessImage) {
            //查找图像
            Element img = doc.select("table.player tr td img").first();
            if (img != null) {
                String imgSrc = img.attr("src"); //获取src属性的值
                if (!StringUtils.isEmpty(imgSrc)) {
                    processImage(baseUrl + "/" + imgSrc, id);
                }
            }
        }

        Elements tables = doc.select("table.player table");
        //成员基本信息
        Element row1 = tables.get(0);
        PersonFromWeb person = new PersonFromWeb();
        person.setId(id);
        processRow1(row1, person);
        //成员技能信息1
        Element row2 = tables.get(1);
        processRow2(row2, person);
        //成员技能信息2
        Element row3 = tables.get(2);
        processRow3(row3, person);
        //成员踢球风格
        Element row4 = tables.get(3);
        processRow4(row4, person);
        return person;
//        personList.add(person);
    }

    private static void processRow4(Element row4, PersonFromWeb person) {
        Elements trs = row4.select(TBODYTR);
        int times = 0;
        String style = "";
        String skills = "";
        String com = "";
        for (Element tr : trs) {
            String td = tr.select("td").text();
            if (td == null || "".equals(td)) {
                times = times + 1;
                continue;
            }
            if (times == 1) {
                style += Constants.COMMA + td;
            } else if (times == 2) {
                skills += Constants.COMMA + td;
            } else {
                com += Constants.COMMA + td;
            }
            person.setStyle(!"".equals(style) ? style.substring(1) : "");
            person.setSkills(!"".equals(skills) ? skills.substring(1) : "");
            person.setCom(!"".equals(com) ? com.substring(1) : "");
        }
    }

    private static void processRow3(Element row3, PersonFromWeb person) {
        Elements trs = row3.select(TBODYTR);
        for (int i = 0; i < 15; i++) {
            String td = trs.get(i).select("td").last().text();
            processRow3(i, person, td, trs);
        }
    }

    private static void processRow3(int i, PersonFromWeb person, String td, Elements trs) {
        switch (i) {
            case 0:
                person.setPhysical(td);
                break;
            case 1:
                person.setJump(td);
                break;
            case 2:
                person.setStamina(td);
                break;
            case 3:
                person.setGoalkeeping(td);
                break;
            case 4:
                person.setCatching(td);
                break;
            case 5:
                person.setClearing(td);
                break;
            case 6:
                person.setReflexes(td);
                break;
            case 7:
                person.setCoverage(td);
                break;
            case 8:
                person.setForm(td);
                break;
            case 9:
                person.setInjury(td);
                break;
            case 10:
                person.setWeakfootusage(td);
                break;
            case 11:
                person.setWeakfootaccuracy(td);
                break;
            case 12:
                break;
            case 13:
                person.setOverall(td);
                break;
            case 14:
                person.setRating(processRating(trs.get(i).select("th").first()));
                break;
            default:
                break;
        }
    }

    private static Map<String, String> processRating(Element th) {
        Element select = th.getElementById("select_rating_as");
        Elements options = select.select("option");
        Map<String, String> map = new HashMap<>();
        for (Element option : options) {
            Document doc = Jsoup.parse(option.val());
            map.put(option.text(), doc.text());
        }
        return map;
    }

    private static void processRow2(Element row2, PersonFromWeb person) {
        Elements trs = row2.select(TBODYTR);
        for (int i = 0; i < 15; i++) {
            String td = trs.get(i).select("td").last().text();
            processRow2(i, person, td);
        }
    }

    private static void processRow2(int i, PersonFromWeb person, String td) {
        switch (i) {
            case 0:
                person.setAttacking(td);
                break;
            case 1:
                person.setBallcontrol(td);
                break;
            case 2:
                person.setDribbling(td);
                break;
            case 3:
                person.setLow(td);
                break;
            case 4:
                person.setLofted(td);
                break;
            case 5:
                person.setFinishing(td);
                break;
            case 6:
                person.setPlace(td);
                break;
            case 7:
                person.setSwerve(td);
                break;
            case 8:
                person.setHeader(td);
                break;
            case 9:
                person.setDefensive(td);
                break;
            case 10:
                person.setBallwinning(td);
                break;
            case 11:
                person.setKicking(td);
                break;
            case 12:
                person.setSpeed(td);
                break;
            case 13:
                person.setExplosive(td);
                break;
            case 14:
                person.setBody(td);
                break;
            default:
                break;
        }
    }

    private static void processRow1(Element row1, PersonFromWeb person) {
        Elements trs = row1.select(TBODYTR);
        for (Element element : trs) {
            String th = "";
            if (element.toString().contains("th")) {
                th = element.select("th").first().text();
            }
            String td = element.select("td").last().text();
            if (th.contains("Player Name")) {
                person.setName(td);
            } else if (th.contains("Squad Number")) {
                person.setNumber(td);
            } else if (th.contains("Team Name")) {
                person.setTeamName(td);
            } else if (th.contains("League")) {
                person.setLeague(td);
            } else if (th.contains("Nationality")) {
                person.setNationality(td);
            } else if (th.contains("Region")) {
                person.setRegion(td);
            } else if (th.contains("Height")) {
                person.setHeight(td);
            } else if (th.contains("Weight")) {
                person.setWeight(td);
            } else if (th.contains("Age")) {
                person.setAge(td);
            } else if (th.contains("Foot")) {
                person.setFoot(td);
            } else if (th.contains("Condition")) {
                person.setCondition(td);
            } else if (th.contains("Position")) {
                person.setPosition(td);
            } else {
                if (element.select("td").last().select("div") != null) {
                    person.setPositionCan(processPosition(element.select("td").last()));
                }
            }
        }
    }

    private static Map<Integer, Set<String>> processPosition(Element td) {
        Set<String> pos0 = new HashSet<>();
        Set<String> pos1 = new HashSet<>();
        Set<String> pos2 = new HashSet<>();
        Element div1 = td.select("div.posFW").first();
        if (null != div1) {
            processSpan(div1, 0, pos0);
            processSpan(div1, 1, pos1);
            processSpan(div1, 2, pos2);
        }
        Element div2 = td.select("div.posMF").first();
        if (null != div2) {
            processSpan(div2, 0, pos0);
            processSpan(div2, 1, pos1);
            processSpan(div2, 2, pos2);
        }
        Element div3 = td.select("div.posDF").first();
        if (null != div3) {
            processSpan(div3, 0, pos0);
            processSpan(div3, 1, pos1);
            processSpan(div3, 2, pos2);
        }
        Element div4 = td.select("div.posGK").first();
        if (null != div4) {
            processSpan(div4, 0, pos0);
            processSpan(div4, 1, pos1);
            processSpan(div4, 2, pos2);
        }
        Map<Integer, Set<String>> map = new HashMap<>();
        map.put(0, pos0);
        map.put(1, pos1);
        map.put(2, pos2);
        return map;
    }

    private static void processSpan(Element div, Integer num, Set<String> pos) {
        String cssQuery = "span.pos" + num;
        Elements spans = div.select(cssQuery);
        if (spans != null && !spans.isEmpty()) {
            if (num.equals(0)) {
                pos.addAll(spans.eachText());
            } else if (num.equals(1)) {
                pos.addAll(spans.eachText());
            } else if (num.equals(2)) {
                pos.addAll(spans.eachText());
            }
        }
    }

    private static void processPage() {
        //加载第一页
        allPageList.add(baseUrl);
        Integer startPage = 2;
        Integer totalPage = 299;
        String url;
        for (int i = startPage; i < totalPage; i++) {
            url = "http://pesdb.net/pes2018/?page=" + i;
            allPageList.add(url);
        }
    }

    private static void getPlayerPageList(Document doc) {
        Element table = doc.select("table.players").first();
        Elements links = table.select("a[href]");
        for (Element link : links) {
            String linkHref = link.attr("href");
            if (linkHref.contains("./?id=")) {
                String newUrl = baseUrl + linkHref.replaceFirst(".", "");
                playerPageList.add(newUrl);
            }
        }
    }

    /**
     * 导出为Excel
     *
     * @param list 列表
     */
    public static void exportToExcel(List<PersonFromWeb> list) {
        FileOutputStream out;
        String folderPath = "d://football" + File.separator;
        try {
            File folder = new File(folderPath);
            if (!folder.exists()) {
                Boolean isCreateDir = folder.mkdirs();
                log.info(isCreateDir.toString());
            }

            String fileName = System.currentTimeMillis() + ".xls";
            File file = new File(folderPath, fileName);
            if (!file.exists()) {
                Boolean isCreateFile = file.createNewFile();
                log.info(isCreateFile.toString());
            }

            out = new FileOutputStream(file.getPath());
            HSSFWorkbook workbook = new HSSFWorkbook();
            HSSFSheet sheet = workbook.createSheet("sheet1");
            HSSFRow row;
            HSSFCell cell;
            sheet.createFreezePane(0, 1);
            HSSFFont font = workbook.createFont();
            font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
            HSSFCellStyle style = workbook.createCellStyle();
            style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
            style.setFont(font);
            style.setWrapText(true);
            String[] title = {Constants.ID, "Player Name", "Squad Number", "Team Name", "League", "Nationality", "Region", "Height", "Weight",
                    "Age", "Foot", "Position", "pos", "Attacking Prowess", "Ball Control", "Dribbling", "Low Pass",
                    "Lofted Pass", "Finishing", "Place Kicking", "Swerve", "Header", "Defensive Prowess",
                    "Ball Winning", "Kicking Power", "Speed", "Explosive Power", "Body Balance", "Jump", "Stamina",
                    "Goalkeeping", "Catching", "Clearing", "Reflexes", "Coverage", "Form", "Injury Resistance",
                    "Weak Foot Usage", "Weak Foot Accuracy", "Overall Rating", "Playing Style", "Player Skills", "COM Playing Style", "Rating as"};
            row = sheet.createRow(0);
            for (int i = 0; i < title.length; i++) {
                cell = row.createCell(i);
                cell.setCellValue(title[i]);
            }
            int i = 1;
            for (PersonFromWeb person : list) {
                row = sheet.createRow(i++);
                cell = row.createCell(0);
                cell.setCellValue(person.getId());
                cell = row.createCell(1);
                cell.setCellValue(person.getName());
                cell = row.createCell(2);
                cell.setCellValue(person.getNumber());
                cell = row.createCell(3);
                cell.setCellValue(person.getTeamName());
                cell = row.createCell(4);
                cell.setCellValue(person.getLeague());
                cell = row.createCell(5);
                cell.setCellValue(person.getNationality());
                cell = row.createCell(6);
                cell.setCellValue(person.getRegion());
                cell = row.createCell(7);
                cell.setCellValue(person.getHeight());
                cell = row.createCell(8);
                cell.setCellValue(person.getWeight());
                cell = row.createCell(9);
                cell.setCellValue(person.getAge());
                cell = row.createCell(10);
                cell.setCellValue(person.getFoot());
                cell = row.createCell(11);
                cell.setCellValue(person.getPosition());
                cell = row.createCell(12);
                cell.setCellValue(JSONObject.toJSONString(person.getPositionCan()));
                cell = row.createCell(13);
                cell.setCellValue(person.getAttacking());
                cell = row.createCell(14);
                cell.setCellValue(person.getBallcontrol());
                cell = row.createCell(15);
                cell.setCellValue(person.getDribbling());
                cell = row.createCell(16);
                cell.setCellValue(person.getLow());
                cell = row.createCell(17);
                cell.setCellValue(person.getLofted());
                cell = row.createCell(18);
                cell.setCellValue(person.getFinishing());
                cell = row.createCell(19);
                cell.setCellValue(person.getPlace());
                cell = row.createCell(20);
                cell.setCellValue(person.getSwerve());
                cell = row.createCell(21);
                cell.setCellValue(person.getHeader());
                cell = row.createCell(22);
                cell.setCellValue(person.getDefensive());
                cell = row.createCell(23);
                cell.setCellValue(person.getBallwinning());
                cell = row.createCell(24);
                cell.setCellValue(person.getKicking());
                cell = row.createCell(25);
                cell.setCellValue(person.getSpeed());
                cell = row.createCell(26);
                cell.setCellValue(person.getExplosive());
                cell = row.createCell(27);
                cell.setCellValue(person.getBody());
                cell = row.createCell(28);
                cell.setCellValue(person.getJump());
                cell = row.createCell(29);
                cell.setCellValue(person.getStamina());
                cell = row.createCell(30);
                cell.setCellValue(person.getGoalkeeping());
                cell = row.createCell(31);
                cell.setCellValue(person.getCatching());
                cell = row.createCell(32);
                cell.setCellValue(person.getClearing());
                cell = row.createCell(33);
                cell.setCellValue(person.getReflexes());
                cell = row.createCell(34);
                cell.setCellValue(person.getCoverage());
                cell = row.createCell(35);
                cell.setCellValue(person.getForm());
                cell = row.createCell(36);
                cell.setCellValue(person.getInjury());
                cell = row.createCell(37);
                cell.setCellValue(person.getWeakfootusage());
                cell = row.createCell(38);
                cell.setCellValue(person.getWeakfootaccuracy());
                cell = row.createCell(39);
                cell.setCellValue(person.getOverall());
                cell = row.createCell(40);
                cell.setCellValue(person.getStyle());
                cell = row.createCell(41);
                cell.setCellValue(person.getSkills());
                cell = row.createCell(42);
                cell.setCellValue(person.getCom());
                cell = row.createCell(43);
                cell.setCellValue(JSONObject.toJSONString(person.getRating()));
            }
            workbook.write(out);
            out.flush();
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
            log.error(e.getMessage());
            throw new MyException(ExceptionEnum.INPUTEXCEPTION, e);
        }
    }

    /**
     * 根据图像地址获取图像到本地
     *
     * @param urlString url地址
     * @param name      名称
     * @return 是否成功
     */
    public static boolean processImage(String urlString, String name) {
        try {
            //new一个URL对象
            URL url = new URL(urlString);
            //打开链接
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            //设置请求方式为"GET"
            conn.setRequestMethod("GET");
            //超时响应时间为5秒
            conn.setConnectTimeout(5 * 1000);
            int result = conn.getResponseCode();
            if (result == 200) {
                //通过输入流获取图片数据
                InputStream inStream = conn.getInputStream();
                //得到图片的二进制数据，以二进制封装得到数据，具有通用性
                byte[] data = readInputStream(inStream);
                //new一个文件对象用来保存图片，默认保存当前工程根目录
                File imageFile = new File("d:\\head\\" + name + ".png");
                //创建输出流
                FileOutputStream outStream = new FileOutputStream(imageFile);
                //写入数据
                outStream.write(data);
                //关闭输出流
                outStream.close();
                return true;
            }
        } catch (IOException e) {
            log.error(e.getMessage());
            throw new MyException(ExceptionEnum.INPUTEXCEPTION, e);
        }
        return false;
    }

    /**
     * 根据图像地址获取图像到本地
     *
     * @param baseUrl url地址
     * @param name    名称
     * @return 是否成功
     */
    public static String processImageUrl(String baseUrl, String name) throws Exception {
        Document doc = Jsoup.connect(baseUrl + name)
                .userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31")
                .timeout(5000)
                .get();
        Element img = doc.select("img.player_head").first();
        return "http://www.pesmaster.com" + img.attr("src");
    }

    /**
     * 根据图像地址获取图像到本地
     *
     * @param urlString url地址
     * @param name      名称
     * @return 是否成功
     */
    public static PersonFromWeb processPerson(String urlString, String name, boolean isProcessImage) {
        Document doc = null;
        try {
            doc = Jsoup.connect(urlString)
                    .userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31")
                    .timeout(5000)
                    .get();
        } catch (IOException e) {
            log.error(e.getMessage());
            return null;
        }
        return processPlayerList(doc, name, isProcessImage);
    }

    /**
     * 根据图像地址获取图像到本地
     *
     * @param urlString url地址
     * @return 是否成功
     */
    public static Map<String, String> processPage(String baseUrl, String urlString) {
        Map<String, String> map = new HashMap<>();
        try {
            Document doc = Jsoup.connect(urlString)
                    .userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31")
                    .timeout(5000)
                    .get();
            Element table = doc.select("table.players").first();
            Elements links = table.select("a[href]");
            for (Element link : links) {
                String linkHref = link.attr("href");
                if (linkHref.contains("./?id=")) {
                    String newUrl = baseUrl + linkHref.replaceFirst(".", "");
                    String num = linkHref.replace("./?id=", "");
                    map.put(num, newUrl);
                }
            }
        } catch (IOException e) {
            log.error(e.getMessage());
            throw new MyException(ExceptionEnum.INPUTEXCEPTION, e);
        }
        return map;
    }

    private static byte[] readInputStream(InputStream inStream) throws IOException {
        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        //创建一个Buffer字符串
        byte[] buffer = new byte[1024];
        //每次读取的字符串长度，如果为-1，代表全部读取完毕
        int len;
        //使用一个输入流从buffer里把数据读取出来
        while ((len = inStream.read(buffer)) != -1) {
            //用输出流往buffer里写入数据，中间参数代表从哪个位置开始读，len代表读取的长度
            outStream.write(buffer, 0, len);
        }
        //关闭输入流
        inStream.close();
        //把outStream里的数据写入内存
        return outStream.toByteArray();
    }

    /**
     * 读取某个文件夹下的所有文件
     */
    public static boolean readfile(String filepath) throws IOException {
        try {
            File file = new File(filepath);
            if (file.isDirectory()) {
                String[] filelist = file.list();
                if (filelist != null) {
                    for (String fileStr : filelist) {
                        File readfile = new File(filepath + "\\" + fileStr);
                        if (!readfile.isDirectory()) {
                            processExcel(readfile);
                        }
                    }
                }
                wirteExcel();
            }
        } catch (FileNotFoundException e) {
            log.info("readfile()   Exception:" + e.getMessage());
        }
        return true;
    }

    private static void wirteExcel() throws IOException {
        HSSFWorkbook newExcelCreat = new HSSFWorkbook();
        HSSFSheet newSheet = newExcelCreat.createSheet("Sheet1");
        log.info(rows.size() + "");
        for (int i = 0; i < rows.size(); i++) {//遍历每个sheet
            HSSFRow row = rows.get(i);
            HSSFRow newRow = newSheet.createRow(i);
            copyRow(row, newRow);
        }
        FileOutputStream fileOut = new FileOutputStream("d://result.xls");
        newExcelCreat.write(fileOut);
        fileOut.flush();
        fileOut.close();
    }

    private static void processExcel(File readfile) throws IOException {
        HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(readfile));
        HSSFSheet sheet = workbook.getSheetAt(0);
        for (int j = 1; j < sheet.getLastRowNum() + 1; j++) {// getLastRowNum，获取最后一行的行标
            HSSFRow row = sheet.getRow(j);
            if (row != null) {
                rows.add(row);
            }
        }
        log.info("读取sheet表：完成");
    }

    private static void copyCell(HSSFCell fromCell, HSSFCell toCell) {
        // 不同数据类型处理
        int fromCellType = fromCell.getCellType();
        toCell.setCellType(fromCellType);
        if (fromCellType == HSSFCell.CELL_TYPE_NUMERIC) {
            toCell.setCellValue(fromCell.getNumericCellValue());
        } else if (fromCellType == HSSFCell.CELL_TYPE_STRING) {
            toCell.setCellValue(fromCell.getRichStringCellValue());
        } else if (fromCellType == HSSFCell.CELL_TYPE_BOOLEAN) {
            toCell.setCellValue(fromCell.getBooleanCellValue());
        } else if (fromCellType == HSSFCell.CELL_TYPE_ERROR) {
            toCell.setCellErrorValue(fromCell.getErrorCellValue());
        } else if (fromCellType == HSSFCell.CELL_TYPE_FORMULA) {
            toCell.setCellFormula(fromCell.getCellFormula());
        }
    }

    private static void copyRow(HSSFRow oldRow, HSSFRow toRow) {
        toRow.setHeight(oldRow.getHeight());
        for (Iterator cellIt = oldRow.cellIterator(); cellIt.hasNext(); ) {
            HSSFCell tmpCell = (HSSFCell) cellIt.next();
            HSSFCell newCell = toRow.createCell(tmpCell.getColumnIndex());
            copyCell(tmpCell, newCell);
        }
    }

    public static void main(String[] args) {
//        SpiderUtil spiderUtil = new SpiderUtil();
        try {
            log.info("start");
            SpiderUtil.readfile("d://football");
            log.info("end");
        } catch (IOException e) {
            e.printStackTrace();
        }
//        log.info(spiderUtil.baseUrl);
    }

    /**
     *
     */
    @Override
    public void run() {
        processPage();
        int j = 1;
        if (allPageList == null || allPageList.isEmpty()) {
            return;
        }
        for (String url : allPageList) {
            log.info("Process Page:" + j++ + "/" + allPageList.size());
            repeartMethod(url, true);
        }
        j = 1;
        if (playerPageList == null || playerPageList.isEmpty()) {
            return;
        }
        for (String url : playerPageList) {
            log.info("Process Detail:" + j++ + "/" + playerPageList.size());
            repeartMethod(url, false);
        }
        exportToExcel(personList);
    }

    private void repeartMethod(String url, boolean isPage) {
        try {
            Document doc = Jsoup.connect(url)
                    .userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31")
                    .timeout(5000)
                    .get();
            if (isPage) {
                getPlayerPageList(doc);
            } else {
                processPlayerList(doc, findIdByUrl(url), true);
            }
            Thread.sleep(1000);
        } catch (IOException e) {
            log.error("Jsoup IOError:" + e.getMessage());
//            repeartMethod(url, isPage);
            throw new MyException(ExceptionEnum.INPUTEXCEPTION, e);
        } catch (InterruptedException e) {
            log.info("Thread Error:" + e.getMessage());
            Thread.currentThread().interrupt();
            throw new MyException(ExceptionEnum.INTERRUPTEDEXCEPTION, e);
        }
    }
}
